<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
</head>
<body>
<div class="layui-container" style="width: 960px;height: 600px;margin-top: 0px;padding-top: 60px;">

    <div style="margin-left: 460px; width: 300px;">
        <a href="/account/redirect/index">首页</a>&nbsp;&nbsp;|&nbsp;&nbsp;欢迎回来！<a href="/account/redirect/order" ></a><a href="/account/logout">&nbsp;&nbsp;&nbsp;<button class="layui-btn layui-btn-warm layui-btn-radius">退出</button></a>
    </div>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
    </script>
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <script th:src="@{/layui/layui.all.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/jquery-3.4.1.js}"></script>
    <script>
        layui.use('table', function(){
            var table = layui.table;
            var token = layui.data('token').data;
            var user = layui.data('user').data;
            table.render({
                elem: '#test'
                ,url:'/order/findByUId/'+user[0].id
                ,title: '订单列表'
                ,headers : {'token': token }
                ,cols: [
                    [
                        {field:'orderId', width:100, title: '编号', sort: true}
                        , {field: 'total_price', width: 200, title: '总价'}
                        , {field: 'logoUrl', width: 100, title: 'logoUrl'}
                        , {field:'date',width:210,  title: '下单时间'}
                        , {field:'state', width:160, title: '订单状态',templet:function(data){
                                var result = "";
                                switch (data.state) {
                                    case 0:
                                        result = "未派送";
                                        break;
                                    case 1:
                                        result = "已派送";
                                        break;
                                }
                                return result
                            }
                        }

                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:160}
                    ]
                ]
                ,page: true
            });

            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                if(obj.event === 'show'){
                    layui.data('detail', {
                        key: 'data',
                        value: [
                        ]
                    });
                    console.log(data.orderDetailList);
                    window.location.href="/user/redirect/order_detail";

                }
            });
        });
    </script>

</div>
<script>
    //二级菜单联动
    layui.use('element', function(){
        var element = layui.element;

    });
</script>
</body>
</html>